package br.com.sgdc.view;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.Label;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

import br.com.sgdc.view.action.ActionEsqueceuSenhaLabelWindowLogin;
import br.com.sgdc.view.action.ActionLogarButtonWindowLogin;
import br.com.sgdc.view.util.Imagens;

public class WindowLogin {
	public JDialog window = new JDialog();
	
	public JLabel usuarioLabel = new JLabel("Usuario",Label.LEFT);
	public JLabel senhaLabel = new JLabel("Senha",Label.LEFT);
	public JLabel esqueceuSenhaLabel = new JLabel("Esqueceu a senha!",Label.LEFT);
	
	public JTextField usuarioTextField = new JTextField();
	public JPasswordField senhaPasswordField = new JPasswordField(15);
	
	public JButton logarButton = new JButton("Logar");

	public WindowLogin() {
		window.setTitle(".:: SGDC - Login ::.");
		window.setLayout(new BorderLayout());
		window.setSize(370, 150);
		window.setLocationRelativeTo(null);
		window.setIconImage(new ImageIcon(getClass().getResource(Imagens.cloud)).getImage());
	}
	
	public void initComponentesJanela() {
		this.iniiComponentes();
		
		window.setLayout(new BorderLayout());
		window.add(BorderLayout.CENTER,constructPrincipalPanel());
		window.add(BorderLayout.SOUTH,constructSouthPanel());
		window.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		window.setVisible(true);
	}
	
	private void iniiComponentes() {
		esqueceuSenhaLabel.setForeground(Color.BLUE);
		logarButton.setIcon(new ImageIcon(getClass().getResource(Imagens.ok)));
		
		this.contructAction();
	}
	
	private JPanel constructPrincipalPanel() {
		JPanel panelGrid = new JPanel();
		panelGrid.setLayout(new GridLayout(4,2));
		panelGrid.add(usuarioLabel);
		panelGrid.add(usuarioTextField);
		
		panelGrid.add(senhaLabel);
		panelGrid.add(senhaPasswordField);
		
		panelGrid.add(new JPanel());
		panelGrid.add(new JPanel());
		
		panelGrid.add(new JPanel());
		panelGrid.add(logarButton);
		
		JPanel panelFlow = new JPanel();
		panelFlow.setLayout(new FlowLayout(FlowLayout.CENTER));
		panelFlow.add(panelGrid);
		
		return panelFlow;
	}
	
	private JPanel constructSouthPanel() {
		JPanel panelSouth = new JPanel();
		panelSouth.setLayout(new FlowLayout(FlowLayout.CENTER));
		panelSouth.add(esqueceuSenhaLabel);
		
		return panelSouth;
	}
	
	private void contructAction() {
		logarButton.addActionListener(new ActionLogarButtonWindowLogin(this));
		esqueceuSenhaLabel.addMouseListener(new ActionEsqueceuSenhaLabelWindowLogin(this));
	}
}
